import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppComponent } from './app.component';
import { Product1Component } from './product1/product1.component';
import {ProductService} from "./shared/product.service";
import { Product2Component } from './product2/product2.component';
import {LoggerService} from "./shared/logger.service";
import {AnotherProductService} from "./shared/another-product.service";


@NgModule({
  declarations: [
    AppComponent,
    Product1Component,
    Product2Component
  ],
  imports: [
    BrowserModule
  ],
  providers: [{
    provide: ProductService,
    useFactory: (logger:LoggerService, isDev) => {
      if(isDev){
        return new ProductService(logger);
      }else {
        return new AnotherProductService(logger);
      }
    },
    deps:[LoggerService, "IS_DEV_ENY"]
  },LoggerService,
    {
      provide: "IS_DEV_ENY", useValue: false
    }],
  bootstrap: [AppComponent]
})
export class AppModule { }

// useFactory: (logger:LoggerService, appConfig) => {
//   if(appConfig.isDev){
//     return new ProductService(logger);
//   }else {
//     return new AnotherProductService(logger);
//   }
// },
//   deps:[LoggerService, "IS_DEV_ENY"]
// },LoggerService,
//   {
//     provide: "APP_CONFIG", useValue: {isDev: false}
//   }],
